package com.demo.core.common.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

/**
 * 类描述:
 * 默认成功，返回结果时，如果出现异常，在异常捕获时时状态值为错误
 *
 * @author housy
 * 创建时间: 2021年6月03日 下午4:04:02
 * 版本： V1.0.0
 */
@Data
@NoArgsConstructor
public class Result {

    /**
     * 返回结果
     *
     * @mock 1
     */
    private String resultCode;

    /**
     * 返回结果描述
     *
     * @mock success
     */
    private String resultDes;

    // 返回结果正确代码
    public static final String SUCCESS_CODE = "0000";

    // 返回结果正确描述
    public static final String SUCCESS_DESC = "success";

    /**
     * 参数校验返回码
     */
    public static final String ERROR_CODE_400 = "400";

    // 返回结果错误代码
    public static final String ERROR_CODE = "5000";

    // 返回结果默认错误描述
    public static final String ERROR_DESC = "error";

    // 用户请求资源超限的错误
    public static final String SECURE_LIMIT_CODE = "9999";

    // 号段效验错误
    public static final String LIMIT_USER_AREA_CODE = "9996";

    public static final String UNKNOWN_EXCEPTION = "未知异常";



    /**
     * 用户未登录的提示
     */
    public static final String NOT_LOGGED_CODE = "503";

    public static final String NOT_LOGGED_DESC = "用户未登录";

    public static final String SYSTEM_BUSY = "系统繁忙，稍后再试！";

    public static final String OPERATION_BUSY = "操作太频繁了，请稍后重试！";

    public static final String PARAMETER_ERROR = "操作太频繁了，请稍后重试！";

    public static final String INTERNET_ERROR = "网络错误，请稍后再试";

    public static final String NO_DATA = "暂无数据";

    public static final String NOT_PHONE_ACTIVITY = "请输入查询的活动名称或手机号码";

    public static final String EXPIRED_LOGGED_DESC = "用户未认证，请重新进入！";

    /**
     * 活动下线
     */
    public static final String ACTIVITIES_OFFLINE = "9997";

    /**
     * 活动到期
     */
    public static final String ACTIVITIES_EXPIRES = "9995";

    private static final Result RESULT_SUCCESS = new Result(SUCCESS_CODE, SUCCESS_DESC);

    public Result(String resultCode, String resultDes) {
        this.resultCode = resultCode;
        this.resultDes = resultDes;
    }

    public static Result success() {
        return RESULT_SUCCESS;
    }

    /**
     * errorResult:返回错误结果.<br/>
     *
     * @return
     */
    public static Result error() {
        return new Result(ERROR_CODE, ERROR_DESC);
    }

    /**
     * errorResult:返回自定义错误描述结果.<br/>
     *
     * @param errorDesc
     * @return
     */
    public static Result error(String errorDesc) {
        return new Result(ERROR_CODE, errorDesc);
    }

    public static Result error(String code, String errorDesc) {
        if (StringUtils.isEmpty(code)) {
            code = ERROR_CODE;
        }
        return new Result(code, errorDesc);
    }

    public static Result success(String succDesc) {
        return new Result(SUCCESS_CODE, succDesc);
    }
}
